package com.shanghaiyimu.yimiyangche.fragment;


import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;


/**
 * A simple {@link Fragment} subclass.
 */
public class WenDaFragment extends Fragment implements View.OnClickListener{


    public WenDaFragment() {
        // Required empty public constructor
    }
    private Fragment f1,f2,f3;
    private TextView t1,t2,t3;
    private FragmentManager manager;
    private FragmentTransaction transaction;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_faxian, container, false);
        initView(view);
        return view;
    }


    private void initView(View view) {

        t1 = (TextView) view.findViewById(R.id.hot_tie);
        t1.setTextColor(Color.RED);
        t2 = (TextView) view.findViewById(R.id.what_bankuai);
        t3 = (TextView) view.findViewById(R.id.bankuai);
        t1.setOnClickListener(this);
        t2.setOnClickListener(this);
        t3.setOnClickListener(this);

        f1 = new HotTieFragment();
        f2 = new WhatBanKuaiFragment();
        f3 = new BanKuaiFragment();

        manager = getFragmentManager();
        transaction = manager.beginTransaction();

        transaction.add(R.id.faxian_fragment_framelayout,f1);
        transaction.add(R.id.faxian_fragment_framelayout,f2);
        transaction.add(R.id.faxian_fragment_framelayout,f3);

        transaction.show(f1);
        transaction.hide(f2);
        transaction.hide(f3);

        transaction.commit();


    }

    @Override
    public void onClick(View v) {
        FragmentTransaction transaction1 = manager.beginTransaction();

        switch (v.getId()){
            case R.id.hot_tie:
                t1.setTextColor(Color.RED);
                t2.setTextColor(Color.BLACK);
                t3.setTextColor(Color.BLACK);
                transaction1.show(f1);
                transaction1.hide(f2);
                transaction1.hide(f3);

                break;
            case R.id.what_bankuai:
                t2.setTextColor(Color.RED);
                t1.setTextColor(Color.BLACK);
                t3.setTextColor(Color.BLACK);
                transaction1.show(f2);
                transaction1.hide(f1);
                transaction1.hide(f3);
                break;
            case R.id.bankuai:
                transaction1.show(f3);
                transaction1.hide(f2);
                transaction1.hide(f1);
                t3.setTextColor(Color.RED);
                t2.setTextColor(Color.BLACK);
                t1.setTextColor(Color.BLACK);
                break;

        }
        transaction1.commit();

    }
}
